package com.ruoyi.factorydata.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.factorydata.domain.WorkOrderLog;
import com.ruoyi.factorydata.service.IWorkOrderLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工单生产记录Controller
 *
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/workOrder/workOrderLog")
public class WorkOrderLogController extends BaseController {
    @Autowired
    private IWorkOrderLogService workOrderLogService;

    /**
     * 查询工单生产记录列表
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:query')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderLog workOrderLog) {
        startPage();
        List<WorkOrderLog> list = workOrderLogService.selectWorkOrderLogList(workOrderLog);
        return getDataTable(list);
    }

    /**
     * 导出工单生产记录列表
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:export')")
    @Log(title = "工单生产记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrderLog workOrderLog) {
        List<WorkOrderLog> list = workOrderLogService.selectWorkOrderLogList(workOrderLog);
        ExcelUtil<WorkOrderLog> util = new ExcelUtil<WorkOrderLog>(WorkOrderLog.class);
        util.exportExcel(response, list, "工单生产记录数据");
    }

    /**
     * 获取工单生产记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(workOrderLogService.selectWorkOrderLogById(id));
    }

    /**
     * 新增工单生产记录
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:add')")
    @Log(title = "工单生产记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderLog workOrderLog) {
        return toAjax(workOrderLogService.insertWorkOrderLog(workOrderLog));
    }

    /**
     * 修改工单生产记录
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:edit')")
    @Log(title = "工单生产记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderLog workOrderLog) {
        return toAjax(workOrderLogService.updateWorkOrderLog(workOrderLog));
    }

    /**
     * 删除工单生产记录
     */
    @PreAuthorize("@ss.hasPermi('workOrder:workOrderLog:remove')")
    @Log(title = "工单生产记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workOrderLogService.deleteWorkOrderLogByIds(ids));
    }
}
